/**
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function main(): int {
    let failCounter: int = 0;
    let testResult: int = 0;
    {% for test_name, test_data in item.method_test_index_data.items() %}
    {%- if item.method_expected_exception is defined %}
    testResult = checkTestResult({{.item.method_name}}{{.test_name|capitalize}}())
    {%- else %}
    let expectedData{{.test_name|capitalize}} : {{.item.result_type}} = {{.item.method_expected_data[test_name]}}
    testResult = checkTestResult({{.item.func_name}}{{.test_name|capitalize}}(), expectedData{{.test_name|capitalize}})
    {%- endif %}
    printTestVerdict(testResult, "{{.test_name}}")
    failCounter += testResult
    {% endfor %}
    if (failCounter > 0) return 1
    return 0;
}

function printTestVerdict(flag: int, testName: String) {
    if (flag == 0) {
      console.println(testName + " : PASSED")
    } else {
      console.println(testName + " : FAILED")
    }
}
